/*
 *  Class name: Book.java
 *  Version: 1.0
 *  Date: 21.6.2014
 */
package cz.morosystems.personwebmanager.persistencelayer.entities;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Michal Ďuriš
 */
@Entity
public class Book implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    @Size(min = 1, max = 20, message = "Titul musí byť zadaný! (max. 20 znakov)")
    @Column(length = 20, nullable = false)
    private String title;

    @Size(max = 40)
    @Column(length = 40)
    private String description;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + Objects.hashCode(this.id);
        hash = 97 * hash + Objects.hashCode(this.title);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {

        if (obj == null) {
            return false;
        }

        if (!(obj instanceof Book)) {
            return false;
        }

        final Book other = (Book) obj;

        if (!Objects.equals(this.id, other.id)) {
            return false;
        }

        return Objects.equals(this.title, other.title);
    }

    @Override
    public String toString() {
        return "cz.morosystems.personwebmanager.persistencelayer.entities.Book[ id=" + id + " ]";
    }

}
